package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceTenancy;
import com.ruoyi.service.service.IServiceTenancyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租赁信息Controller
 * 
 * @author yepanpan
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/service/tenancy")
public class ServiceTenancyController extends BaseController
{
    @Autowired
    private IServiceTenancyService serviceTenancyService;

    /**
     * 查询租赁信息列表
     */
    @PreAuthorize("@ss.hasPermi('service:tenancy:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceTenancy serviceTenancy)
    {
        startPage();
        List<ServiceTenancy> list = serviceTenancyService.selectServiceTenancyList(serviceTenancy);
        return getDataTable(list);
    }

    /**
     * 导出租赁信息列表
     */
    @PreAuthorize("@ss.hasPermi('service:tenancy:export')")
    @Log(title = "租赁信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceTenancy serviceTenancy)
    {
        List<ServiceTenancy> list = serviceTenancyService.selectServiceTenancyList(serviceTenancy);
        ExcelUtil<ServiceTenancy> util = new ExcelUtil<ServiceTenancy>(ServiceTenancy.class);
        util.exportExcel(response, list, "租赁信息数据");
    }

    /**
     * 获取租赁信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:tenancy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceTenancyService.selectServiceTenancyById(id));
    }

    /**
     * 新增租赁信息
     */
    @PreAuthorize("@ss.hasPermi('service:tenancy:add')")
    @Log(title = "租赁信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceTenancy serviceTenancy)
    {
                serviceTenancy.setCreateBy(getUsername());
        return toAjax(serviceTenancyService.insertServiceTenancy(serviceTenancy));
    }

    /**
     * 修改租赁信息
     */
    @PreAuthorize("@ss.hasPermi('service:tenancy:edit')")
    @Log(title = "租赁信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceTenancy serviceTenancy)
    {
                serviceTenancy.setUpdateBy(getUsername());
        return toAjax(serviceTenancyService.updateServiceTenancy(serviceTenancy));
    }

    /**
     * 删除租赁信息
     */
    @PreAuthorize("@ss.hasPermi('service:tenancy:remove')")
    @Log(title = "租赁信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceTenancyService.deleteServiceTenancyByIds(ids));
    }
}
